﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;

namespace WebSys.UI.Control.ZhengShou
{
    public class Admin_cont_newControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox txtCaseid, txtFyh, txtSqr, txtDfr, txtAy, txtBz, txtID;
        MPCalendar txtPjrq;
        DropDownList ddlFyzt;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            string strid = base.Page.Request["ID"];
            string strcaseid = base.Page.Server.UrlDecode(base.Page.Request["caseid"]);
            //string strcaseid = string.Empty;
            //if (!string.IsNullOrEmpty(strcaseiid)) {
            //    string sql = "select caseid from zs_case_register where iid='"+strcaseiid+"'";
            //    strcaseid = _EluZSDataProvider.GetSomeStr("(" + sql + ")", "*", "");
            //}
            if (string.IsNullOrEmpty(strcaseid))
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("案件号未填写！", "window.close();");
            }
            if (!base.Page.IsPostBack)
            {
                QSDATADLL();
                if (!string.IsNullOrEmpty(strcaseid)) { txtCaseid.Text = strcaseid; }
                if (string.IsNullOrEmpty(strid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } 
                else { 
                    txtID.Text = strid;
                    EluZSProvider.BCJDXZFY bcjdxzfy = _EluZSDataProvider.GetBCJDXZFY(strid);
                    txtCaseid.Text = bcjdxzfy.CASEID;
                    txtFyh.Text = bcjdxzfy.FYH;
                    txtSqr.Text = bcjdxzfy.SQR;
                    txtDfr.Text = bcjdxzfy.DFR;
                    txtAy.Text = bcjdxzfy.AY;

                    txtBz.Text = bcjdxzfy.BZ;
                    if (bcjdxzfy.PJRQ.HasValue) { txtPjrq.Text = bcjdxzfy.PJRQ.Value.ToShortDateString(); }
                    ddlFyzt.SelectedValue = bcjdxzfy.FYZT;
                }
            }

            Button btn_Insert = (Button)FindControl("btn_Insert");
            btn_Insert.Click += new EventHandler(btn_Insert_Click);
        }
        protected void InitControl() {
            txtCaseid = (TextBox)FindControl("txtCaseid");
            txtFyh = (TextBox)FindControl("txtFyh");
            txtSqr = (TextBox)FindControl("txtSqr");
            txtDfr = (TextBox)FindControl("txtDfr");
            txtAy = (TextBox)FindControl("txtAy");

            txtBz = (TextBox)FindControl("txtBz");
            txtID = (TextBox)FindControl("txtID");
            txtPjrq = (MPCalendar)FindControl("txtPjrq");
            ddlFyzt = (DropDownList)FindControl("ddlFyzt");
        }
        protected void btn_Insert_Click(object sender, EventArgs e)
        {
            EluZSProvider.BCJDXZFY bcjdxzfy = new EluZSProvider.BCJDXZFY();
            string strid = base.Page.Request["ID"];
            bcjdxzfy.ID = txtID.Text;
            bcjdxzfy.CASEID = txtCaseid.Text;
            bcjdxzfy.FYH = txtFyh.Text.Trim();
            bcjdxzfy.SQR = txtSqr.Text.Trim();
            bcjdxzfy.DFR = txtDfr.Text.Trim();

            bcjdxzfy.AY = txtAy.Text.Trim();
            bcjdxzfy.BZ = txtBz.Text.Trim(); 
            bcjdxzfy.PJRQ = (string.IsNullOrEmpty(txtPjrq.Text) ? null : (DateTime?)Convert.ToDateTime(txtPjrq.Text));
            bcjdxzfy.FYZT = ddlFyzt.SelectedValue;

            base.Page.Session["nCount"] = "2";

            bool save = _EluZSDataProvider.SaveBCJDXZFY(strid, bcjdxzfy);

            Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptbasic1", "<script>windowClose('" + base.Page.Request["type"] + "');</script>");
        }
        protected void QSDATADLL() {
            List<EluZSProvider.Params> _params = _EluZSDataProvider.GetParams("复议状态");
            EluZSProvider.Params item = new EluZSProvider.Params();
            item.Keyname = "";
            item.Keyvalue = "0";
            _params.Insert(0, item);
            ddlFyzt.DataSource = _params;
            ddlFyzt.DataValueField = "keyvalue";
            ddlFyzt.DataTextField = "keyname";
            ddlFyzt.DataBind();
        }
    }
}


